#!/usr/bin/perl

use strict;
use warnings;

our $command;

our %commands;

our %aliases;

our @return;

our %globalFunctionRegExp = (
        HISTORY => '-*history',
        MAIL    => '-*mail=(\w+@[\w+\.\w+]+)',
        GREP    => '\|\s*grep\s*(.+)\s*(\|*|$)',
        mORE    => '\|\s*more\s*$',
        NOCOLR  => '-*nocolor',
    );

our %globalFunctionValue = (
    );

&reLoadPlugins();

MAIN: while ( 1 ) {

  print "PROMPT:";
  chomp( $command = <STDIN> );


  # execute command by command!!!
  
  # !end!
  last if ( $command =~ m/^\s*(quit|exit|bye|logout|end)/i );

  &commandSplitterParserExecuter( $command );

  # cut the parameters
  for my $key ( keys %globalFunctionRegExp ) {
    my $value1 = $globalFunctionRegExp{$key};
    my $value2 = $globalFunctionValue{$key};
    # 
    if ( $command =~ s/$value1// ) {
      if ( defined ( $1 ) ) {
        $globalFunctionValue{$key} = $1 if ( defined ( $1 ) );
      }
      else {
        $globalFunctionValue{$key} = "ON";
      }
    }
  }

  for my $key ( keys %globalFunctionRegExp ) {
    my $value1 = $globalFunctionRegExp{$key};
    my $value2 = defined( $globalFunctionValue{$key} ) ? $globalFunctionValue{$key} : "N/A";
    #
    print "$key | $value1 | $value2 \n"
  }

  print "$command\n";

  for my $key ( keys %commands ) {
    if ($command =~ $key) {
      @return = &{$commands{$key}} ($1, $2, $3, $4, $5, $6, $7, $8, $9);
    }
  }

  %globalFunctionValue = (
  );



} # END of MAIN loop

############################################
# reLoad external Exclude list and plugins
############################################
sub reLoadPlugins () {

  %commands = ();
  %aliases = ();

  for( glob("plugins/*") ) {
    print "[$_]\n";
    do $_ || die ("TOTAL FATAL: $!, check this file: [$_] generated");
  }
}
